﻿<Page
    x:Name="PageRoot"
    x:Class="SubtitleRT.PlayerPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:converters="using:SubtitleRT.Converters"
    mc:Ignorable="d">

    <Page.Resources>
        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">Subtitle RT</x:String>
        <converters:TimeSpanToStringConverter x:Key="TimeSpanToStringConverter"/>
    </Page.Resources>
    
    <Page.TopAppBar>
        <AppBar>
            <!-- Back button and page title -->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="280"/>
                    <ColumnDefinition Width="280"/>
                </Grid.ColumnDefinitions>
                <Button Name="BtnHome" Margin="39,0,0,10" Click="BtnHome_OnClick" Grid.Column="0"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Bottom"
                        AutomationProperties.Name="Home"
                        AutomationProperties.AutomationId="HomeButton"
                        AutomationProperties.ItemType="Navigation Button" TabIndex="2"/>
                <TextBlock Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,0,10"/>
                <ComboBox Name="Encodings" Grid.Column="2" Width="220" VerticalAlignment="Center" HorizontalAlignment="Center" ItemsSource="{Binding SupportedEncodings}"
                          SelectedItem="{Binding SelectedEncoding, Mode=TwoWay}" TabIndex="1"/>
                <SearchBox Name="MainSearch" Grid.Column="3" Width="220" VerticalAlignment="Center" HorizontalAlignment="Center" PlaceholderText="Text to search"
                           QuerySubmitted="MainSearch_OnQuerySubmitted" TabIndex="2"/>
            </Grid>
        </AppBar>
    </Page.TopAppBar>

    <Page.BottomAppBar>
        <AppBar>
            <StackPanel Orientation="Horizontal">
                <AppBarButton Name="BtnPlay" Style="{StaticResource PlayAppBarButtonStyle}" Click="BtnPlay_OnClick"/>
                <TextBox Name="TxtTime" Margin="30,10,25,30" Width="120" Text="{Binding Path=CurrentPlayTime, Mode=TwoWay, Converter={StaticResource TimeSpanToStringConverter}}" 
                         VerticalAlignment="Center" TextChanged="TxtTime_OnTextChanged"/>
                <CheckBox Margin ="25,5,0,30" Content="Show timestamps" FontSize="18" IsChecked="{Binding ShowTimestamps, Mode=TwoWay}"/>
            </StackPanel>
        </AppBar>
    </Page.BottomAppBar>
    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <ListView Name="LstSubtitles"  ItemsSource="{Binding Subtitles}" 
                  IsItemClickEnabled="True" ItemClick="LstSubtitles_OnItemClick"
                  SelectionChanged="LstSubtitles_OnSelectionChanged">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" Margin="10,0,0,0" Background="{Binding ItemColor}">
                        <StackPanel Orientation="Horizontal" Visibility="{Binding ExtraInfoVisibility}">
                            <TextBlock Text="{Binding ItemNumber}"/>
                            <TextBlock Text="" Margin="10,0,10,0"/>
                            <TextBlock Text="{Binding StartTime, Converter={StaticResource TimeSpanToStringConverter}}"/>
                            <TextBlock Text="to" Margin="10,0,10,0"/>
                            <TextBlock Text="{Binding EndTime, Converter={StaticResource TimeSpanToStringConverter}}"/>
                        </StackPanel>
                        <ContentControl Content="{Binding RichContent}"/>
                        <!--<TextBlock Text="{Binding Content}" TextWrapping="WrapWholeWords" Margin="8"  FontSize="28"/>-->
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>
